home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tex / macros / source / contrib / fp / fp-snap.sty < prev    next >
Text File  |  1995-03-09  |  6KB  |  241 lines

  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesPackage{fp-snap}[1994/08/10]
  3.  
  4. %version information
  5. \def\FP@snapversion{1.0}
  6. \message{%
  7.   `Fixed Point Snap Off',%
  8.   \space\space\space\space\space\space\space\space\space%
  9.   Version \FP@snapversion%
  10.   \space(C) Michael Mehlich%
  11. }
  12.  
  13. %resolve dependencies
  14. \RequirePackage{fp-basic}
  15.  
  16. %%%public area (macros which may be used)%%%
  17.  
  18. \def\FPround#1#2#3{\FP@calld\FP@round#1{#2}{#3}}
  19. \def\FPtrunc#1#2#3{\FP@calld\FP@trunc#1{#2}{#3}}
  20. \def\FPclip#1#2{\FP@calld\FP@clip#1{#2}}
  21.  
  22. %%%private fp-area (don't use these macros)%%%
  23.  
  24. %round value
  25. \def\FP@round#1#2.#3.#4\relax#5{%
  26.   % #1 macro, which gets the result
  27.   % #2 integer part of value
  28.   % #3 fractional part of value
  29.   % #4 dummy to swallow everything after the second '.'
  30.   % #5 round position
  31.   {\FP@beginmessage{ROUND}%
  32.    %
  33.    \FP@count=#5\relax%
  34.    %
  35.    \ifnum\FP@count<0\relax%
  36.      \FP@errmessage{Rounding value before point not allowed}%
  37.    \else
  38.      \FP@readvalue{x}{#2}{#3}%
  39.      \ifnum\FP@count=0\relax%
  40.         \ifnum\FP@xfa<500000000\relax%
  41.       \edef\FP@tmp{#2}%
  42.     \else%
  43.       \advance\FP@xib1\relax%
  44.       \ifnum\FP@xib<1000000000\relax\else%
  45.         \advance\FP@xia1\relax%
  46.         \advance\FP@xib-1000000000\relax%
  47.       \fi%
  48.       \ifnum\FP@xs<0\relax%
  49.         \edef\FP@tmp{-}%
  50.       \else
  51.         \edef\FP@tmp{}%
  52.       \fi%
  53.       \ifnum\FP@xia=0\relax%
  54.         \edef\FP@tmp{\FP@tmp\the\FP@xib}%
  55.       \else%
  56.         \advance\FP@xib1000000000\relax%
  57.         \edef\FP@tmp{\FP@tmp\the\FP@xia\expandafter\FP@ignorenext\the\FP@xib}%
  58.       \fi%
  59.     \fi%
  60.      \else%
  61.        \ifnum\FP@count>18\relax%
  62.          \FP@count=18\relax%
  63.        \fi%
  64.        \advance\FP@xfa1000000000\relax%
  65.        \advance\FP@xfb1000000000\relax%
  66.        \edef\FP@tmp{\expandafter\FP@ignorenext\the\FP@xfa\expandafter\FP@ignorenext\the\FP@xfb}%
  67.        \edef\FP@rd{}%
  68.        \FP@shift=\FP@count%
  69.        \FP@times=1\relax%
  70.        \loop%
  71.           \ifnum\FP@count>0\relax%
  72.              \edef\FP@rd{\FP@rd\expandafter\FP@first\FP@tmp\noexpand\relax}%
  73.              \edef\FP@tmp{\expandafter\FP@ignorenext\FP@tmp}%
  74.          \advance\FP@count-1\relax%
  75.          \multiply\FP@times10\relax\ifnum\FP@times=1000000000\relax\FP@times=1\relax\fi%
  76.           \repeat%
  77.        \edef\FP@tmp{\expandafter\FP@first\FP@tmp\noexpand\relax}%
  78.        \expandafter\FP@rega\FP@tmp\relax%
  79.        \ifnum\FP@rega>4\relax%
  80.      \ifnum\FP@shift>9\relax%
  81.        \FP@ninesplit\FP@rd%
  82.        \expandafter\FP@rega\FP@rd\relax%
  83.        \advance\FP@rega1\relax%
  84.        \ifnum\FP@rega<\FP@times%
  85.          \advance\FP@rega\FP@times%
  86.          \advance\FP@res1000000000\relax%
  87.        \else%
  88.          \advance\FP@res1\relax%
  89.          \ifnum\FP@res<1000000000\relax%
  90.            \advance\FP@res1000000000\relax%
  91.          \else%
  92.            \advance\FP@xib1\relax%
  93.            \ifnum\FP@xib<1000000000\relax\else%
  94.              \advance\FP@xia1\relax%
  95.              \advance\FP@xib-1000000000\relax%
  96.            \fi%
  97.          \fi%
  98.        \fi%
  99.        \edef\FP@tmpa{\expandafter\FP@ignorenext\the\FP@res\expandafter\FP@ignorenext\the\FP@rega}%
  100.      \else%
  101.        \expandafter\FP@rega\FP@rd\relax%
  102.        \advance\FP@rega1\relax%
  103.        \ifnum\FP@rega<\FP@times%
  104.          \advance\FP@rega\FP@times%
  105.        \else%
  106.          \advance\FP@xib1\relax%
  107.          \ifnum\FP@xib<1000000000\relax\else%
  108.            \advance\FP@xia1\relax%
  109.            \advance\FP@xib-1000000000\relax%
  110.          \fi%
  111.        \fi%
  112.            \edef\FP@tmpa{\expandafter\FP@ignorenext\the\FP@rega}%
  113.      \fi%
  114.        \else%
  115.          \edef\FP@tmpa{\FP@rd}%
  116.        \fi%
  117.        \ifnum\FP@xs<0\relax%
  118.          \edef\FP@tmp{-}%
  119.        \else%
  120.          \edef\FP@tmp{}%
  121.        \fi%
  122.        \ifnum\FP@xia=0\relax%
  123.          \edef\FP@tmp{\FP@tmp\the\FP@xib.\FP@tmpa}%
  124.        \else%
  125.          \advance\FP@xib1000000000\relax%
  126.          \edef\FP@tmp{\FP@tmp\the\FP@xia\expandafter\FP@ignorenext\the\FP@xib.\FP@tmpa}%
  127.        \fi%
  128.      \fi%
  129.    \fi%
  130.    %
  131.    \global\let\FP@tmp\FP@tmp%
  132.    %
  133.    \FP@endmessage{}%
  134.   }%
  135.   \let#1\FP@tmp%
  136. }
  137.  
  138. %trunc value
  139.  
  140. \def\FP@trunc#1#2.#3.#4\relax#5{%
  141.   % #1 macro, which gets the result
  142.   % #2 integer part of value
  143.   % #3 fractional part of value
  144.   % #4 dummy to swallow everything after the second '.'
  145.   % #5 trunc position
  146.   {\FP@beginmessage{TRUNC}%
  147.    %
  148.    \FP@count=#5\relax%
  149.    %
  150.    \ifnum\FP@count<0\relax%
  151.      \FP@errmessage{Truncating value before point not allowed}%
  152.    \else\ifnum\FP@count=0\relax%
  153.      \edef\FP@tmp{#2}%
  154.    \else
  155.      \ifnum\FP@count>18\relax%
  156.        \FP@count=18\relax%
  157.      \fi%
  158.      \FP@readvalue{x}{#2}{#3}%
  159.      \advance\FP@xfa1000000000\relax%
  160.      \advance\FP@xfb1000000000\relax%
  161.      \edef\FP@tmp{\expandafter\FP@ignorenext\the\FP@xfa\expandafter\FP@ignorenext\the\FP@xfb}%
  162.      \edef\FP@tmpa{}%
  163.      \loop%
  164.        \ifnum\FP@count>0\relax%
  165.           \edef\FP@tmpa{\FP@tmpa\expandafter\FP@first\FP@tmp\noexpand\relax}%
  166.           \edef\FP@tmp{\expandafter\FP@ignorenext\FP@tmp}%
  167.       \advance\FP@count-1\relax%
  168.        \repeat%
  169.      \ifnum\FP@xs<0\relax%
  170.        \edef\FP@tmp{-}%
  171.      \else%
  172.        \edef\FP@tmp{}%
  173.      \fi%
  174.      \ifnum\FP@xia=0\relax%
  175.        \edef\FP@tmp{\FP@tmp\the\FP@xib.\FP@tmpa}%
  176.      \else%
  177.        \advance\FP@xib1000000000\relax%
  178.        \edef\FP@tmp{\FP@tmp\the\FP@xia\expandafter\FP@ignorenext\the\FP@xib.\FP@tmpa}%
  179.      \fi%
  180.    \fi\fi%
  181.    %
  182.    \global\let\FP@tmp\FP@tmp%
  183.    %
  184.    \FP@endmessage{}%
  185.   }%
  186.   \let#1\FP@tmp%
  187. }
  188.  
  189. %clip value
  190.  
  191. \def\FP@revert#1#2{%
  192.   % #1 macro, which gets the result
  193.   % #2 value
  194.   {\edef\FP@tmpa{#2}%
  195.    \edef\FP@tmp{}%
  196.    \loop%
  197.      \expandafter\if!\FP@tmpa!\relax\else%
  198.        \edef\FP@tmpb{\expandafter\FP@first\FP@tmpa\noexpand\relax}%
  199.        \edef\FP@tmpa{\expandafter\FP@ignorenext\FP@tmpa}%
  200.        \edef\FP@tmp{\FP@tmpb\FP@tmp}%
  201.      \repeat%
  202.    \global\let\FP@tmp\FP@tmp%
  203.   }%
  204.   \let#1\FP@tmp%
  205. }
  206.  
  207. \def\FP@clip#1#2.#3.#4\relax{%
  208.   % #1 macro, which gets the result
  209.   % #2 integer part of value
  210.   % #3 fractional part of value
  211.   % #4 dummy to swallow everthing after the 2nd '.'
  212.   %
  213.   {\FP@beginmessage{CLIP}%
  214.    %
  215.    \FP@revert\FP@tmpb{#3}%
  216.    \FP@removeleadingzeros\FP@tmpb\relax%
  217.    \FP@revert\FP@tmpb\FP@tmp%
  218.    \edef\FP@tmpa{#2}%
  219.    \FP@removeleadingzeros\FP@tmpa\relax%
  220.    \edef\FP@tmpa{\FP@tmp}%
  221.    \expandafter\if!\FP@tmpa!\relax%
  222.      \expandafter\if!\FP@tmpb!\relax%
  223.        \edef\FP@tmp{0}%
  224.      \else
  225.        \edef\FP@tmp{0.\FP@tmpb}%
  226.      \fi%
  227.    \else%
  228.      \expandafter\if!\FP@tmpb!\relax%
  229.        \edef\FP@tmp{\FP@tmpa}%
  230.      \else%
  231.        \edef\FP@tmp{\FP@tmpa.\FP@tmpb}%
  232.      \fi%
  233.    \fi%
  234.    %
  235.    \global\let\FP@tmp\FP@tmp%
  236.    %
  237.    \FP@endmessage{}%
  238.   }%
  239.   \let#1\FP@tmp%
  240. }
  241.